<?php
class Admin_home_Controller extends Template_Controller {

	public $template = 'admin/index';
	
    public function __construct()
    {
        parent::__construct();
    }
    
    public function index()
    {	
        $this->template->content = new View('admin_home/index');
        
    }
    
    public function sale_summary()
    {
    	$calendar = new Calendar($this->site['site_short_date']);
    	$model = new Order_Model();
    	//All
    	$mlist = $model->get_total();		
		$mr['orders_total'] = $this->format_currency($mlist[0]['orders_total'],$this->site['site_currency']);
		$mr['shipping_total'] = $this->format_currency($mlist[0]['shipping_total'],$this->site['site_currency']);	
		//This week	
		$mlist = $model->get_total($calendar->get_time_start_week(),$calendar->get_time_end_week());
		$mr['orders_total_week'] = $this->format_currency($mlist[0]['orders_total'],$this->site['site_currency']);
		$mr['shipping_total_week'] = $this->format_currency($mlist[0]['shipping_total'],$this->site['site_currency']);
		//This month	
		$mlist = $model->get_total($calendar->get_time_start_month(),$calendar->get_time_end_month());
		$mr['orders_total_month'] = $this->format_currency($mlist[0]['orders_total'],$this->site['site_currency']);
		$mr['shipping_total_month'] = $this->format_currency($mlist[0]['shipping_total'],$this->site['site_currency']);
		//This month	
		$mlist = $model->get_total($calendar->get_time_start_year(),$calendar->get_time_end_year());
		$mr['orders_total_year'] = $this->format_currency($mlist[0]['orders_total'],$this->site['site_currency']);
		$mr['shipping_total_year'] = $this->format_currency($mlist[0]['shipping_total'],$this->site['site_currency']);
		$this->template->content->mr = $mr;
	}
	
    public function sale_info()
    {
    	$model = new Order_Model();
    	$this->db->limit(5);
    	$mlist = $model->get();
		//Format
    	for($i=0; $i<count($mlist);$i++)
		{
		   $mlist[$i]['orders_date'] = $this->format_int_date($mlist[$i]['orders_date'],$this->site['site_short_date']);
		}
		$this->template->content->mlist = $mlist;
	}
	
    public function rma_info()
    {
    	$model = new Rma_Model();
    	$this->db->limit(5);
    	$mlist = $model->get();
		//Format
    	for($i=0; $i<count($mlist);$i++)
		{
		   $mlist[$i]['rma_date'] = $this->format_int_date($mlist[$i]['rma_date'],$this->site['site_short_date']);
		}
		$this->template->content->list_rma = $mlist;
	}
	
	public function new_product()
    {
    	$model = new Product_Model();
    	$this->db->limit(3);
    	$mlist = $model->get();
    	//Format
    	for($i=0; $i<count($mlist);$i++)
		{
		   $mlist[$i]['products_sale_price'] = $this->format_currency($mlist[$i]['products_sale_price'],$this->site['site_currency']);
		   $mlist[$i]['products_wholesale_price'] = $this->format_currency($mlist[$i]['products_wholesale_price'],$this->site['site_currency']);
		}
		$this->template->content->list_product = $mlist;
	}
	
	public function new_customer()
    {
    	$model = new Customer_Model();
    	$this->db->limit(3);
    	$mlist = $model->get();
		$this->template->content->list_customer = $mlist;
	}
}
?>